# -*- coding: utf-8 -*-
"""
Created on Sat Dec 29 22:57:11 2012

@author: Winand
"""

DEBUG = True

import os

#Request handlers are called in specified order
REQUESTHANDLERS = (
    'login',
    'router',
    'lastresort',
)

#Project root dir
ROOTDIR=os.path.dirname(__file__)
#Directory for configs etc.
DATADIR=os.path.normpath(ROOTDIR+"/data") #/var/log/lancomm-dat in real env (?)
#Detect static files requests
STATIC_PREFIX="/static/"

#Logging
LOGFILE=os.path.normpath(DATADIR+"/lancomm.log")
LOG_TO_CONSOLE = DEBUG #False in real env
LOG_LEVEL=10 #20 in real env

#Shared data
SHARED_SERVER_ADDR, SHARED_SERVER_PORT = "127.0.0.1", 50001
#shutdown server if no requests during this period (sec)
SERVER_SHUTDOWN_TIMEOUT = 10 if DEBUG else 300 #TODO: client shouldn't crash after server restart
CONFIG_FLUSH_PERIOD = 1000 if DEBUG else 180 #flush shared data to disk every C._F._P. sec if any changes
SHARED_FILE_STORAGE = os.path.normpath(DATADIR+"/config.dat")
SHARED_NO_PERMANENT = False #do not use file storage

#Authentication
URL_AUTH = "/auth"
URL_HOME = "/"
COOKIE_SESS = "uidsess"
MAX_CONN = 10
MAX_USER = 2
TIMEOUT_SESS = 15 #min
DEFAULT_USER = "admin"

#Mail
SMTP_CFG_FILE="Z:\\smtp.conf" if DEBUG else "/etc/smtp.conf"
MAIL_CFG_FILE="Z:\\alert_email.conf" if DEBUG else "/etc/alert_email.conf"

#Templates
TEMPLATEDIR="/templates/"
#Used in http.templateResponse
TEMPLATEFIELDS = {
    'lasterror': "",
    'creator': "Winand",
    'year_cr': "2012-2013",
}
BASE_HTML = "<!DOCTYPE html><html><body>%s</body></html>"

#Url handlers
SRV_ROOT_PATH = 'srv'
SRV_CONF_ROOT_PATH = 'srvconf'
SRV_AJAX_ROOT_PATH = 'ajax'
URLHANDLERS = {
    '/': 'main_page',
    '/'+SRV_ROOT_PATH+'/.+': 'service_root',
    '/'+SRV_CONF_ROOT_PATH+'/.+': 'service_root',
    '/'+SRV_AJAX_ROOT_PATH+'/.+': 'service_root',
}

SERVICELIST = [
    "tracker",
    "wake",
]

#SERVICES
#Wake
S_WAKE_IFACE = "eth0"
S_WAKE_BROAD = "192.168.1.255" #last-resort broadcast address

#Config
#from webapi.remotedict import RemoteDict
#config = RemoteDict("config")
